home *** CD-ROM | disk | FTP | other *** search
- /* Locare preview hook to read MacPaint (and FullPaint) files.
-
- It reads up to the max size of 285 lines of a MacPaint file and then
- displays these lines.
-
- This hook does NOT illustrate good programming techniques. Defenses
- are practically non-existent. Feel free to use this as an example or
- as a foundation for your own hooks. If you wish to improve upon
- this hook, please do not hesitate.
-
- Written in LightspeedC.
- */
-
-
-
- #include <QuickDraw.h>
- #include <EventMgr.h>
- #include <MacTypes.h>
- #include <FileMgr.h>
- #include <FontMgr.h>
- #include <WindowMgr.h>
-
-
- #define maxsize 20520
-
- typedef struct
- { char version; /* 1 for now */
- char message;
- int volume;
- long directory;
- int index;
- } PreviewRec;
-
-
- pascal void main(infoPtr)
- PreviewRec *infoPtr;
- { char nameString[256];
- ParamBlockRec myHRec;
- int refNum,scanline;
- WindowPtr myWin;
- Rect rect,scrRect;
- Ptr Buffer,dstPtr,saveDstPtr,saveBuffer;
- BitMap theBitMap;
- long size;
-
- myHRec.fileParam.ioFDirIndex = infoPtr->index;
- myHRec.fileParam.ioFlNum = infoPtr->directory;
- myHRec.fileParam.ioVRefNum = infoPtr->volume;
- myHRec.fileParam.ioNamePtr = (StringPtr)nameString;
- PBGetCatInfo(&myHRec,FALSE);
-
- myHRec.fileParam.ioFlNum = infoPtr->directory;
- myHRec.fileParam.ioVRefNum = infoPtr->volume;
- myHRec.fileParam.ioNamePtr = (StringPtr)nameString;
- myHRec.fileParam.filler1 = fsRdPerm; /* LS C's file mgr header
- doesn't offer much support for H Rec's....ioParam offers none.
- I have modified my own header to include H rec's, but maybe
- you haven't. So I just used the available fileParam, where
- filler1 = ioPermssn byte. */
- myHRec.fileParam.ioFDirIndex = 0;
- PBHOpen(&myHRec,FALSE);
- refNum = myHRec.fileParam.ioFRefNum;
- rect.top = 41;
- rect.left = 11;
- rect.right = rect.left + 490;
- rect.bottom = rect.top + 300;
-
- myWin = NewWindow(0L,&rect,nameString,TRUE,noGrowDocProc,-1L,FALSE,0L);
- SetPort(myWin);
- TextFont(monaco);
- TextSize(9);
-
- myHRec.ioParam.ioRefNum = refNum;
- PBGetEOF(&myHRec,FALSE);
- size = (long)myHRec.ioParam.ioMisc - 512; /* sub 512 byte header */
- if(size > maxsize)
- size = maxsize;
-
-
- Buffer = NewPtr(maxsize);
- if(Buffer == 0l)
- { DisposeWindow(myWin);
-
- PBClose(&myHRec,FALSE);
- infoPtr->message = 1;
- return;
- }
- saveBuffer = Buffer;
-
- myHRec.ioParam.ioPosMode = fsFromStart;
- myHRec.ioParam.ioBuffer = Buffer;
- myHRec.ioParam.ioPosOffset = 512;
- myHRec.ioParam.ioReqCount = size;
- PBRead(&myHRec,FALSE);
-
- dstPtr = NewPtr(maxsize);
- if(dstPtr == 0l)
- { DisposeWindow(myWin);
- DisposPtr(Buffer);
-
- PBClose(&myHRec,FALSE);
- infoPtr->message = 1;
- return;
- }
- saveDstPtr = dstPtr;
-
- for(scanline = 0;scanline < 285; scanline++)
- { UnpackBits(&Buffer,&dstPtr,72);
- }
-
- DisposPtr(saveBuffer);
-
- theBitMap.baseAddr = saveDstPtr;
- theBitMap.rowBytes = 72;
- theBitMap.bounds.top = 0;
- theBitMap.bounds.left = 0;
- theBitMap.bounds.right = 72*8;
- theBitMap.bounds.bottom = 285;
-
- rect.top = 0;
- rect.left = 0;
- rect.right = rect.left + 488;
- rect.bottom = rect.top + 285;
-
- CopyBits(&theBitMap,&myWin->portBits,&rect,&rect,srcCopy,0l);
-
- DisposPtr(saveDstPtr);
-
-
- MoveTo(0,285);
- LineTo(490,285);
-
- MoveTo(5,297);
- DrawString("\p'PNTG' file preview hook by Raymond Lau. \
- Please <CLICK> to continue…");
- do
- {}
- while(!Button());
- FlushEvents(mDownMask,0l);
-
- DisposeWindow(myWin);
-
- PBClose(&myHRec,FALSE);
- infoPtr->message = 1;
- return;
- }